<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-22 13:13:43
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-11-09 09:24:11
 * @FilePath: \app-formwork\src\pages\login\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template lang="pug">
view.nearby
  web-view(
    :src="url",
    :update-title="false")
</template>

<script setup>
import { ref, onMounted } from "vue"; // vue相关方法
const vwUrl = ref("http://app.antiraedi.com/h5/#/pagesA/nearby-map/nearby-map");
const h5Url = ref("http://app.antiraedi.com/h5/#/pagesA/nearby-map/nearby-map-h5");
const url = ref();

onMounted(async () => {
  // #ifdef APP-PLUS
  url.value = vwUrl.value;
  // #endif
  // #ifdef H5
  url.value = h5Url.value;
  // #endif
  setWebviewBarHeight();
});

const setWebviewBarHeight = async () => {
  // 使用 async/await 来获取系统信息
  const sysInfo = await uni.getSystemInfo();
  const statusBar = sysInfo.statusBarHeight;
  const height = sysInfo.windowHeight;
  // 获取webview
  let pages = getCurrentPages();
  let page = pages[pages.length - 1];
  let currentWebview = page.$getAppWebview();
  setTimeout(function () {
    var wv = currentWebview.children()[0];
    wv.setStyle({
      // 设置web-view距离顶部的距离以及自己的高度，单位为px
      top: statusBar, // 此处是距离顶部的高度，应该是你页面的头部
      height: height - statusBar // webview的高度
    });
  }, 200); // 如页面初始化调用需要写延迟
};
</script>

<style lang="stylus" scoped></style>
